﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;
namespace CungMuaC5.WebUC
{
    public partial class wucDanhSachDDH : System.Web.UI.UserControl
    {
        private DTO_TaiKhoan CurrentUser;
        
        private BUS_DoanhNghiep bus_DN = new BUS_DoanhNghiep();
        private BUS_DonHang bus_DH = new BUS_DonHang();
        int maTK;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CurrentUser = Session.GetCurrentUser();
                maTK = int.Parse(CurrentUser.MaTK.ToString());
                LayDanhSachDDH();
            }
        }

        public void LayDanhSachDDH()
        {            
            List<DTO_ThongTinDH> danhSachDH;
            int maDN = bus_DN.LayMaDN(maTK);
            danhSachDH = bus_DH.LayDanhSachDonHang(maDN);
            gvDSDDH.DataSource = danhSachDH;
            gvDSDDH.DataBind();
            lblTongSo.Text = danhSachDH.Count.ToString();
            int sum = 0;
            for (int i = 0; i < danhSachDH.Count; i++)
            {
                sum += danhSachDH[i].TongTien;
            }
            lblTongTien.Text = sum.ToString();
        }
        public void LayDanhSachDDH(string madh)
        {
            List<DTO_ThongTinDH> danhSachDH;
            int maDN = bus_DN.LayMaDN(maTK);
            danhSachDH = bus_DH.LayDanhSachDonHang(maDN);            
            gvDSDDH.DataSource = danhSachDH;
            gvDSDDH.DataBind();
            lblTongSo.Text = danhSachDH.Count.ToString();
            int sum = 0;
            for (int i = 0; i < danhSachDH.Count; i++)
            {
                sum += danhSachDH[i].TongTien;
            }
            lblTongTien.Text = sum.ToString();
        }
    }
}